package com.express.wechat.filter;

import com.express.util.UserUtil;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author: laixiangdong
 * @Date 2020/12/09
 */
@WebFilter({"/index.html", "/wechat/*", "/wxUserhome.html", "/userCheckStart.html", "/personQRcode.html", "/wxIdCardUserInfoModify.html", "/lazyboard.html", "/expressList.html", "/expressAssist.html", "/addExpress.html"})
public class UserFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpSession session = ((HttpServletRequest) req).getSession();
        String userPhone = UserUtil.getWechatUserPhone(session);
        if (userPhone != null) {
            chain.doFilter(req, resp);
        } else {
            ((HttpServletResponse) resp).sendRedirect("/login.html");
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
